<template>
    <div>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>编辑公告</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="putNoticeInfo">保存</el-button>
        </div>
        <div >
          <el-input
            type="textarea"
            :rows="7"
            placeholder="请输入内容"
            v-model="noticeInfo"
            maxlength="500"
            show-word-limit>
          </el-input>
        </div>
      </el-card>

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span style="margin-right: 10px;">平台提示</span>
          <span>
            <el-button style=" float: right; padding: 3px 0" type="text" @click="putTipInfo">保存</el-button>
            <el-switch v-model="value" active-color="#ff4949" inactive-color="#13ce66" @change="putCloseProject"></el-switch>
          </span>

        </div>
        <div >
          <el-input
            type="textarea"
            :rows="7"
            placeholder="请输入内容"
            v-model="tipInfo"
            maxlength="500"
            show-word-limit>
          </el-input>
        </div>
      </el-card>
    </div>
</template>

<script>

    export default {
        name: 'PlacardEdit',
        props: {},
        data(){
            return {
              value: true,
              noticeInfo: '',
              tipInfo:''
            };
        },
        methods: {
          getNoticeInfo(){
            this.$http.get('/v1/dictionaries/notice')
            .then(res =>{
              console.log(res)
              if (res.status === 200){
                this.noticeInfo = res.data;
              }
            })
            .catch(err=>{
              let {response} = err
              if (response){
                this.$message.error(response.data.message);
                return false;
              }else {
                console.log(err)
              }
            })
          },
          putNoticeInfo(){
            let params = {notice: this.noticeInfo}
            this.$http.put('/v1/dictionaries/notice', params)
            .then(res =>{
              console.log(res)
            })
            .catch(err=>{
              let {response} = err
              if (response){
                this.$message.error(response.data.message);
                return false;
              }else {
                console.log(err)
              }
            })
          },
          getTipInfo(){
            let params = {type: 'TIP'}
            this.$http.get('/v1/dictionaries/getOne', {params})
            .then(res =>{
              console.log(res)
              if (res.status === 200){
                this.tipInfo = res.data;
              }
            })
            .catch(err=>{
              let {response} = err
              if (response){
                this.$message.error(response.data.message);
                return false;
              }else {
                console.log(err)
              }
            })
          },
          putTipInfo(){
            let params = {tip: this.tipInfo}
            this.$http.put('/v1/dictionaries/tip', params)
            .then(res =>{
              console.log(res)
            })
            .catch(err=>{
              let {response} = err
              if (response){
                this.$message.error(response.data.message);
                return false;
              }else {
                console.log(err)
              }
            })
          },
          isCloseProject(){
            let params = {type: 'CLOSE_PROJECT'}
            this.$http.get('/v1/dictionaries/getOne', {params})
            .then(res =>{
              console.log(res)
              if (res.status === 200){
                this.value = res.data;
              }
            })
            .catch(err=>{
              let {response} = err
              if (response){
                this.$message.error(response.data.message);
                return false;
              }else {
                console.log(err)
              }
            })
          },
          putCloseProject(){
            let params = {value: this.value}
            this.$http.put('/v1/dictionaries/project', params)
            .then(res =>{
              console.log(res)
            })
            .catch(err=>{
              let {response} = err
              if (response){
                this.$message.error(response.data.message);
                return false;
              }else {
                console.log(err)
              }
            })
          }
        },
      created() {
          this.getNoticeInfo();
          this.getTipInfo();
          this.isCloseProject();
      }


    }

</script>

<style lang="scss" scoped>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    /*display: inline-block;*/
    width: auto;
  }

</style>
